<?php
/**
 * alltosun.com 词库  thesaurus.php
 * ============================================================================
 * 版权所有 (C) 2009-2012 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 王德康 (wangdk@alltosun.com) $
 * $Date: 2012-12-13 下午2:10:39 $
 */

require ROOT_PATH.'/helper/PHPMailer-5.2.9/PHPMailerAutoload.php';

class email_widget
{
    /**
     * 邮件提醒
     */
    public function thumb_mail($title)
    {
        $to[0]  = 'wangdk@alltosun.com';
        $header= 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
        $title = 'make_wookmark_thumb '.$title;
        $content = date('Y-m-d H:i:s');
        $this->send_email($to, $title, $content);
    }

    /**
     * 邮件提醒
     */
    public function mail($to, $title, $content, $path)
    {
        $header= 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
        // $content = $content."- \nIP:". Request::getClientIp();
        return $this->send_email($to, $title, $content, $path);
    }

    /**
     * 发送邮件函数
     * @param string $email 邮箱地址·
     * @param array $search 被替换的内容
     * @param array $replace 替换的内容
     */
    public  function send_email($email, $title = '', $content = '', $path = '')
    {
        /*$headers = "Content-type:text/html; charset=utf-8"."\r\n";
         $headers .= "From: ".ADMIN_EMAIL;//ADMIN_EMAIL

        $title = "=?UTF-8?B?".base64_encode($title)."?=";
        mail($email, $title, $content, $headers);
        return;*/
        // define('ADMIN_EMAIL_BAOBAOTANG',   'alltosun419@163.com');
        // 实例化phpmailer
        $mail = new PHPMailer();
        // 设置发送邮件的协议：SMTP
        $mail->IsSMTP();
        // 发送邮件的服务器
        $mail->Host = "smtp.163.com";
        // 打开SMTP
        $mail->SMTPAuth = true;
        // SMTP账户
        $mail->Username = "15988861092";
        //是否使用HTML格式
        $mail->IsHTML(true);
        // SMTP密码
        $mail->Password = "123456a";
        $mail->From = '15988861092@163.com';
        $mail->FromName = "抱抱堂";
        if (is_array($email)) {
        	foreach ($email as $v) {
        	    $mail->AddAddress("$v", "");
        	}
        } else {
        	    $mail->AddAddress("$email", "");
        }

        if ($path) {
            $filename = basename($path);
            $mail->AddAttachment($path,$filename); // 添加附件,并指定名称
        }

        //设置字符集编码
        $mail->CharSet = "UTF-8";
        $mail->Subject = "=?UTF-8?B?".base64_encode($title)."?=";
        //邮件内容（可以是HTML邮件）
        $mail->Body = $content;
        if (!$mail->Send()) {
            return false;
        } else {
            return true;
        }
    }


}
?>
